package severlet;

import bean.Guarantee;
import dao.GuaranteeDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet(name = "AdminGuaranteeButtonServlet", value = "/AdminGuaranteeButtonServlet")
public class AdminGuaranteeButtonServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        String dormitoryid = request.getParameter("dormitoryid");
        String studentname = request.getParameter("studentname");
        String goodsname = request.getParameter("goodsname");
        String reason = request.getParameter("reason");
        String phoneid = request.getParameter("phoneid");
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Date guaranteetime=null;
        try {
            guaranteetime = sdf.parse(request.getParameter("guaranteetime"));
        } catch (ParseException e) {
            e.printStackTrace();
            request.getRequestDispatcher("FanHui.jsp").forward(request,response);
        }
        String guaranteestaus = request.getParameter("guaranteestaus");
        //封装
        Guarantee guarantee=new Guarantee();
        guarantee.setDormitoryid(dormitoryid);
        guarantee.setStudentname(studentname);
        guarantee.setGoodsname(goodsname);
        guarantee.setReason(reason);
        guarantee.setPhoneid(phoneid);
        guarantee.setGuaranteetime(guaranteetime);
        guarantee.setGuaranteestaus(guaranteestaus);
        //调用dao层
        GuaranteeDao guaranteeDao=new GuaranteeDao();
        //根据宿舍号，姓名修改报修状态,保修时间
        guaranteeDao.changeGuarangeeStaus(guarantee);

        //
        request.getRequestDispatcher("/AdminGuaranteeServlet").forward(request,response);
    }
}
